﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace PhysicsEngine.Dynamics
{
  public class MassData
  {
    public float Mass { get; private set; }
    public float InverseMass { get; private set; }

    public MassData(float mass)
    {
      Contract.Requires<ArgumentException>(mass >= 0);
      Contract.Ensures(Mass == mass);
      Contract.Ensures(InverseMass == 0 || InverseMass == 1/Mass);

      Mass = mass;

      if (Mass == 0)
      {
        InverseMass = 0;
      }
      else
      {
        InverseMass = 1 / Mass;
      }
    }

    [ContractInvariantMethod]
    private void ObjectInvariant()
    {
      Contract.Invariant(Mass >= 0);
      Contract.Invariant(InverseMass >= 0);
    }
  }
}
